(function ($) {
     $.extend({
          imageManager: {
               /**
                *
                * @param clickElem 点击的元素的id
                * @param viewElem  显示的元素的id
                * @param callElem  回写的元素id（为后面form提交使用，可以不传）
                */
               uploadImage: function (url, clickElem, viewElem,callElem) {
                    layui.use('upload', function () {
                         var $ = layui.jquery;
                         var upload = layui.upload;
                         var uploadInst = upload.render({
                              elem: '#' + clickElem,
                              url: url, //改成您自己的上传接口
                              before: function (obj) {
                                   //预读本地文件示例，不支持ie8
                                   obj.preview(function (index, file, result) {
                                        //$('#demo1').attr('src', result); //图片链接（base64）
                                   });
                              }
                              , done: function (res) {
                                   //如果上传失败
                                   if (res.code > 0) {
                                        return layer.msg('上传失败');
                                   }
                                   //上传成功
                                   if(viewElem){
                                        $('#'+viewElem).attr('src', res.url);
                                   }

                                   if (callElem) {
                                        $('#'+callElem ).val(res.url);
                                   }

                              }
                              , error: function () {
                                   //演示失败状态，并实现重传
                                   return layer.msg('上传失败');
                              }
                         });
                    });
               },
               uploadImages:function (url,clickElem, viewElem) {
                    layui.use('upload', function () {
                         var $ = layui.jquery;
                         var upload = layui.upload;

                         upload.render({
                              elem: '#' + clickElem,
                              url: url, //改成您自己的上传接口
                              multiple: true,
                              before: function (obj) {
                                   //预读本地文件示例，不支持ie8
                                   obj.preview(function (index, file, result) {
                                        $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                                   });
                              }
                              , done: function (res) {
                                   $('#' + viewElem).prepend('<img width="150" height="150" src="' + res.url +    '" class="product-img">')
                              }
                         });
                    });
               }
          }
     })
})(jQuery);

